package com.si.anddos.dpadapters;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.format.Time;
import android.util.Log;

/**
 * A class for Database operations with accounts, downloads and uploads
 * 
 * @author Carlos Martinez
 * 
 */
public class AnddosDbAdapter {

	
	///////////////////////////////
	
	public static final String HistorialTable = "Historial";
	public static final String colHistorialID = "_id";
	public static final String colHistorialName = "Name";
	public static final String colHistorialExtension="Extension";
	public static final String colHistorialNumberResults="Results";
	public static final String colHistorialNumberSearchs="Searchs";
	public static final String colHistorialProviderRapidshare="ProviderRapidshare";
	public static final String colHistorialProviderMegaupload="ProviderMegaupload";
	public static final String colHistorialProviderHotfile="ProviderHotfile";
	public static final String colHistorialProviderFileserve="ProviderFileserve";
	public static final String colHistorialProviderFilesonic="ProviderFilesonic";
	public static final String colHistorialProviderMegashares="ProviderMegashares";

	//////////////////////////
	private static final String dbName = "anddosDB";
	private static final int dbVersion = 9;
	private static final String TAG = "AnddosDbAdapter";
	public static final String accountsTable = "Accounts";
	public static final String colAccountID = "_id";
	public static final String colAccountUsername = "Username";
	public static final String colAccountPassword = "Password";
	public static final String colAccountService = "Service";

	public static final String downloadsTable = "Downloads";
	public static final String colDownloadID = "_id";
	public static final String colDownloadDateTime = "Datetime";
	public static final String colDownloadUrl = "Url";
	public static final String colDownloadFilename = "Filename";
	public static final String colDownloadStatus = "Status";
	public static final String colDownloadPriority = "Priority";
	public static final String colDownloadAccount = "Account";

	public static final String uploadsTable = "Uploads";
	public static final String colUploadID = "_id";
	public static final String colUploadFilepath = "Filepath";
	public static final String colUploadFilename = "Filename";
	public static final String colUploadStatus = "Status";
	public static final String colUploadAccount = "Account";

	private static final String triggerDownAccFK = "fk_downacc_accid";
	private static final String triggerUpAccFK = "fk_upacc_accid";
	public static final String viewDownloads = "ViewDownloads";
	public static final String viewUploads = "ViewUploads";

	public static final int StatusWaiting = 0;
	public static final int StatusProcessing = 1;
	public static final int StatusError = 2;
	public static final int StatusDone = 3;
	public static final int StatusStopped = 4;

	public static final int PriorityLow = 0;
	public static final int PriorityNormal = 1;
	public static final int PriorityHigh = 2;

	private DatabaseHelper dbHelper;
	private SQLiteDatabase db;

	private final Context context;

	private static class DatabaseHelper extends SQLiteOpenHelper {

		DatabaseHelper(Context context) {
			super(context, dbName, null, dbVersion);
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			// create database
			
			////////////////////////
			try{db.execSQL("CREATE TABLE IF NOT EXISTS " + HistorialTable + " ("
					+ colHistorialID + " INTEGER PRIMARY KEY, "
					+ colHistorialName + " TEXT NOT NULL , "
					+ colHistorialExtension + " TEXT NOT NULL , "
					+ colHistorialNumberResults + " TEXT NOT NULL , "
					+ colHistorialNumberSearchs + " TEXT NOT NULL , "
					+ colHistorialProviderRapidshare + " TEXT NOT NULL , "
					+ colHistorialProviderMegaupload + " TEXT NOT NULL , "
					+ colHistorialProviderFileserve + " TEXT NOT NULL , "
					+ colHistorialProviderFilesonic + " TEXT NOT NULL , "
					+ colHistorialProviderMegashares + " TEXT NOT NULL , "
					+ colHistorialProviderHotfile + " TEXT NOT NULL)"); 
			}
			catch(SQLException e){
				Log.v(HistorialTable, e.getMessage());
				
			}
			
			//////////////////////////////////
			db.execSQL("CREATE TABLE IF NOT EXISTS " + accountsTable + " ("
					+ colAccountID + " INTEGER PRIMARY KEY AUTOINCREMENT , "
					+ colAccountService + " TEXT NOT NULL , "
					+ colAccountUsername + " TEXT NOT NULL , "
					+ colAccountPassword + " TEXT NOT NULL )");

			db.execSQL("CREATE TABLE IF NOT EXISTS " + downloadsTable + " ("
					+ colDownloadID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
					+ colDownloadDateTime + " TEXT NOT NULL, " + colDownloadUrl
					+ " TEXT NOT NULL, " + colDownloadFilename
					+ " TEXT NOT NULL, " + colDownloadStatus
					+ " INTEGER NOT NULL, " + colDownloadPriority
					+ " INTEGER NOT NULL, " + colDownloadAccount
					+ " INTEGER NOT NULL, FOREIGN KEY (" + colDownloadAccount
					+ ") REFERENCES " + accountsTable + " (" + colAccountID
					+ "));");

			db.execSQL("CREATE TABLE IF NOT EXISTS " + uploadsTable + " ("
					+ colUploadID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
					+ colUploadFilepath + " TEXT NOT NULL, "
					+ colUploadFilename + " TEXT NOT NULL, " + colUploadStatus
					+ " INTEGER NOT NULL, " + colUploadAccount
					+ " INTEGER NOT NULL, FOREIGN KEY (" + colUploadAccount
					+ ") REFERENCES " + accountsTable + " (" + colAccountID
					+ "));");

			db.execSQL("CREATE TRIGGER IF NOT EXISTS " + triggerDownAccFK + " "
					+ " BEFORE INSERT " + " ON " + downloadsTable
					+ " FOR EACH ROW BEGIN" + " SELECT CASE WHEN ((SELECT "
					+ colAccountID + " FROM " + accountsTable + " WHERE "
					+ colAccountID + "=new." + colDownloadAccount
					+ " ) IS NULL)"
					+ " THEN RAISE (ABORT,'Foreign Key Violation') END;"
					+ "  END;");

			db.execSQL("CREATE TRIGGER IF NOT EXISTS " + triggerUpAccFK + " "
					+ " BEFORE INSERT " + " ON " + uploadsTable
					+ " FOR EACH ROW BEGIN" + " SELECT CASE WHEN ((SELECT "
					+ colAccountID + " FROM " + accountsTable + " WHERE "
					+ colAccountID + "=new." + colUploadAccount + " ) IS NULL)"
					+ " THEN RAISE (ABORT,'Foreign Key Violation') END;"
					+ "  END;");

			db.execSQL("CREATE VIEW IF NOT EXISTS " + viewDownloads
					+ " AS SELECT " + downloadsTable + "." + colDownloadID
					+ " AS _id," + " " + downloadsTable + "."
					+ colDownloadDateTime + "," + " " + downloadsTable + "."
					+ colDownloadUrl + "," + " " + downloadsTable + "."
					+ colDownloadFilename + "," + " " + downloadsTable + "."
					+ colDownloadStatus + "," + " " + downloadsTable + "."
					+ colDownloadAccount + "," + " " + downloadsTable + "."
					+ colDownloadPriority + "," + " " + accountsTable + "."
					+ colAccountUsername + "," + " " + accountsTable + "."
					+ colAccountPassword + "," + " " + accountsTable + "."
					+ colAccountService + "" + " FROM " + downloadsTable
					+ " JOIN " + accountsTable + " ON " + downloadsTable + "."
					+ colDownloadAccount + " =" + accountsTable + "."
					+ colAccountID);

			db.execSQL("CREATE VIEW " + viewUploads + " AS SELECT "
					+ uploadsTable + "." + colUploadID + " AS _id," + " "
					+ uploadsTable + "." + colUploadFilepath + "," + " "
					+ uploadsTable + "." + colUploadFilename + "," + " "
					+ uploadsTable + "." + colUploadStatus + "," + " "
					+ uploadsTable + "." + colUploadAccount + "," + " "
					+ accountsTable + "." + colAccountUsername + "," + " "
					+ accountsTable + "." + colAccountPassword + "," + " "
					+ accountsTable + "." + colAccountService + "" + " FROM "
					+ uploadsTable + " JOIN " + accountsTable + " ON "
					+ uploadsTable + "." + colUploadAccount + " ="
					+ accountsTable + "." + colAccountID);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
					+ newVersion + ", which will destroy all old data");
			db.execSQL("DROP TABLE IF EXISTS " + downloadsTable);
			db.execSQL("DROP TABLE IF EXISTS " + accountsTable);
			db.execSQL("DROP TABLE IF EXISTS " + uploadsTable);
			
			///////////////////////////////
			
			db.execSQL("DROP TABLE IF EXISTS " + HistorialTable);
			
			////////////////////////

			db.execSQL("DROP TRIGGER IF EXISTS " + triggerDownAccFK);
			db.execSQL("DROP TRIGGER IF EXISTS " + triggerUpAccFK);
			db.execSQL("DROP VIEW IF EXISTS " + viewDownloads);
			db.execSQL("DROP VIEW IF EXISTS " + viewUploads);
			onCreate(db);
		}
	}

	public AnddosDbAdapter(Context context) {
		this.context = context;
	}

	/**
	 * Open the accounts database. If it cannot be opened, try to create a new
	 * instance of the database. If it cannot be created, throw an exception to
	 * signal the failure
	 * 
	 * @return this (self reference, allowing this to be chained in an
	 *         initialization call)
	 * @throws SQLException
	 *             if the database could be neither opened or created
	 */
	public AnddosDbAdapter open() throws SQLException {
		dbHelper = new DatabaseHelper(context);
		db = dbHelper.getWritableDatabase();
		return this;
	}

	public void close() {
		dbHelper.close();
	}
	
	
	
	////////////////////////////////////////////////////////////////////
	
	/**
	 * Create a new Historial element.
	 * If the element is successfully created return the new rowId for that
	 * element, otherwise return a -1 to indicate failure.
	 * 
	 * @param name
	 *            the word that was searched
	 * @return rowId or -1 if failed
	 */
	public long createHistorialElement(long id,String name,String ext,String numberSearchs,
			String numberResults,String rapidshare,String megaupload,String filesonic,
			String fileserve,String megashares,String hotfile) {
		ContentValues initialValues = new ContentValues();
		initialValues.put(colHistorialName, name);
		initialValues.put(colHistorialID, id);
		initialValues.put(colHistorialExtension, ext);
		initialValues.put(colHistorialNumberResults, numberResults);
		initialValues.put(colHistorialNumberSearchs, numberSearchs);
		initialValues.put(colHistorialProviderRapidshare, rapidshare);
		initialValues.put(colHistorialProviderMegaupload, megaupload);
		initialValues.put(colHistorialProviderMegashares, megashares);
		initialValues.put(colHistorialProviderFilesonic, filesonic);
		initialValues.put(colHistorialProviderFileserve, fileserve);
		initialValues.put(colHistorialProviderHotfile, hotfile);
		
		
		return db.insert(HistorialTable, null, initialValues);
	}
	
	
	/**
	 * Delete the element of the Historial with the given rowId
	 * 
	 * @param rowId
	 *            id of element to delete
	 * @return true if deleted, false otherwise
	 */
	
	public boolean deleteHistorialElement(long rowId) {
		return db.delete(HistorialTable, colHistorialID + "=" + rowId, null) > 0;
	}
	
	
	
	public boolean updateHistorialElement(long id, String name,long newid,String newext,
			String newnumberSearchs,String newnumberResults,String rapidshare,
			String megaupload,String filesonic,String fileserve,String megashares,
			String hotfile) {
		
		ContentValues initialValues = new ContentValues();
		
		// dateTime.format("%Y-%m-%d %H:%M")
		// The same as format("%Y%m%dT%H%M%S").

		initialValues.put(colHistorialName, name);
		initialValues.put(colHistorialID, newid);
		initialValues.put(colHistorialExtension, newext);
		initialValues.put(colHistorialNumberResults, newnumberResults);
		initialValues.put(colHistorialNumberSearchs, newnumberSearchs);
		initialValues.put(colHistorialProviderRapidshare, rapidshare);
		initialValues.put(colHistorialProviderMegaupload, megaupload);
		initialValues.put(colHistorialProviderMegashares, megashares);
		initialValues.put(colHistorialProviderFilesonic, filesonic);
		initialValues.put(colHistorialProviderFileserve, fileserve);
		initialValues.put(colHistorialProviderHotfile, hotfile);
		
		int res = db.update(HistorialTable, initialValues, colDownloadID + "=?", new String[] { String.valueOf(id) });
		if(res != 1)
			return false;
		return true;
	}
	

	public long getNumberHistorialElements() {
		Cursor cur=null;
		String sql="SELECT * FROM "+HistorialTable;
		long aux=-1;
		try{
			cur = db.rawQuery(sql,null);
		}
		catch(SQLException e){
			Log.v(HistorialTable, e.getMessage());
		}
		catch(Exception e1){
			Log.v(HistorialTable,e1.getMessage());
		}
		aux=cur.getCount();
		cur.close();
		return aux;
	}
	
	public long getOlderHistorialElement(){
		Cursor cur=null;
		long aux=0;
		try{
			cur= db.rawQuery("SELECT MIN("+colHistorialID+") FROM " + HistorialTable, null);
			cur.moveToFirst();
		}
		catch(SQLException e){
			Log.v(HistorialTable, e.getMessage());
		}
		catch(Exception e1){
			Log.v(HistorialTable,e1.getMessage());
		}
		if(!cur.isNull(0))
			aux=Long.parseLong(cur.getString(0));
		cur.close();
		return aux;
	}
	
	public long getNewerHistorialElement(){
		Cursor cur=null;
		long aux=0;
		try{
			cur= db.rawQuery("SELECT MAX("+colHistorialID+") FROM " + HistorialTable, null);
			cur.moveToFirst();
		}
		catch(SQLException e){
			Log.v(HistorialTable, e.getMessage());
		}
		catch(Exception e1){
			Log.v(HistorialTable,e1.getMessage());
		}
		if(!cur.isNull(0))
			aux=Long.parseLong(cur.getString(0));
		cur.close();
		return aux;
	}
	
	public Cursor getAllHistorialElements() {
		return db.query(HistorialTable, new String[] { colHistorialID,
				colHistorialName,colHistorialExtension,colHistorialNumberSearchs,
				colHistorialNumberResults,colHistorialProviderRapidshare,colHistorialProviderMegaupload,
				colHistorialProviderFilesonic,colHistorialProviderFileserve,colHistorialProviderMegashares,
				colHistorialProviderHotfile},
				null, null, null, null, colHistorialID+" DESC");
	}
	
	public Cursor getHistorialElement(long rowId) {
		Cursor mCursor = db.query(true, HistorialTable, new String[] {
				colHistorialID,colHistorialName,colHistorialExtension,colHistorialNumberSearchs,
				colHistorialNumberResults,colHistorialProviderRapidshare,
				colHistorialProviderMegaupload,colHistorialProviderFilesonic,
				colHistorialProviderFileserve,colHistorialProviderMegashares,
				colHistorialProviderHotfile}, colHistorialID + "=" + rowId, null, null,
				null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		return mCursor;
	}
	//////////////////////////////////////////////////////////////////////
	
	
	

	/**
	 * Create a new account using the service, username and password provided.
	 * If the account is successfully created return the new rowId for that
	 * account, otherwise return a -1 to indicate failure.
	 * 
	 * @param service
	 *            the service of the account (rapidshare,...)
	 * @param username
	 *            the username of the account
	 * @param password
	 *            the password of the account
	 * @return rowId or -1 if failed
	 */
	public long createAccount(String service, String username, String password) {
		ContentValues initialValues = new ContentValues();
		initialValues.put(colAccountService, service);
		initialValues.put(colAccountUsername, username);
		initialValues.put(colAccountPassword, password);

		return db.insert(accountsTable, null, initialValues);
	}

	/**
	 * Delete the account with the given rowId
	 * 
	 * @param rowId
	 *            id of account to delete
	 * @return true if deleted, false otherwise
	 */
	public boolean deleteAccount(long rowId) {
		return db.delete(accountsTable, colAccountID + "=" + rowId, null) > 0;
	}

	/**
	 * Return a Cursor over the list of all accounts in the database
	 * 
	 * @return Cursor over all accounts
	 */
	public Cursor getAllAccounts() {
		return db.query(accountsTable, new String[] { colAccountID,
				colAccountService, colAccountUsername, colAccountPassword },
				null, null, null, null, null);
	}

	/**
	 * Return a Cursor positioned at the account that matches the given rowId
	 * 
	 * @param rowId
	 *            id of account to retrieve
	 * @return Cursor positioned to matching account, if found
	 * @throws SQLException
	 *             if account could not be found/retrieved
	 */
	public Cursor getAccount(long rowId) throws SQLException {

		Cursor mCursor = db.query(true, accountsTable, new String[] {
				colAccountID, colAccountService, colAccountUsername,
				colAccountPassword }, colAccountID + "=" + rowId, null, null,
				null, null, null);
		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		return mCursor;

	}

	public long createDownload(Time dateTime, String url, String fileName,
			long accountId) {
		ContentValues initialValues = new ContentValues();
		initialValues.put(colDownloadDateTime, dateTime.format2445());
		// dateTime.format("%Y-%m-%d %H:%M")
		// The same as format("%Y%m%dT%H%M%S").

		initialValues.put(colDownloadUrl, url);
		initialValues.put(colDownloadFilename, fileName);
		initialValues.put(colDownloadStatus, StatusWaiting);
		initialValues.put(colDownloadPriority, PriorityNormal);
		initialValues.put(colDownloadAccount, accountId);

		return db.insert(downloadsTable, null, initialValues);
	}

	public boolean deleteDownload(long rowId) {
		return db.delete(downloadsTable, colDownloadID + "=" + rowId, null) > 0;
	}

	public Cursor getAllDownloads() {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewDownloads + " order by " + colDownloadStatus, null);
		return cur;
	}

	public Cursor getAllWaitingDownloads() {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewDownloads + " WHERE "
				+ colDownloadStatus + "=" + StatusWaiting + " ORDER BY "
				+ colDownloadDateTime, null);
		return cur;
	}

	public Cursor getDownload(long id) {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewDownloads + " WHERE "
				+ colDownloadID + "=" + id, null);
		if (cur != null) {
			cur.moveToFirst();
		}
		return cur;
	}

	public boolean updateDownload(long id, Time dateTime, String url, String fileName, int status, int priority, long accountId) {
		
		ContentValues initialValues = new ContentValues();
		initialValues.put(colDownloadDateTime, dateTime.format2445());
		// dateTime.format("%Y-%m-%d %H:%M")
		// The same as format("%Y%m%dT%H%M%S").

		initialValues.put(colDownloadUrl, url);
		initialValues.put(colDownloadFilename, fileName);
		initialValues.put(colDownloadStatus, status);
		initialValues.put(colDownloadPriority, priority);
		initialValues.put(colDownloadAccount, accountId);
		
		int res = db.update(downloadsTable, initialValues, colDownloadID + "=?", new String[] { String.valueOf(id) });
		if(res != 1)
			return false;
		return true;
	}

	/**
	 * @deprecated
	 * @param rowId
	 * @return
	 */
	public boolean updateDownloadDone(long rowId) {
		ContentValues args = new ContentValues();
		args.put(colDownloadStatus, StatusDone);

		return db.update(downloadsTable, args, colDownloadID + "=" + rowId,
				null) > 0;
	}

	// Upload methods

	public long createUpload(String filePath, String fileName, long accountId) {
		ContentValues initialValues = new ContentValues();
		initialValues.put(colUploadFilepath, filePath);
		initialValues.put(colUploadFilename, fileName);
		initialValues.put(colUploadStatus, StatusWaiting);
		initialValues.put(colUploadAccount, accountId);

		return db.insert(uploadsTable, null, initialValues);
	}

	public boolean deleteUpload(long rowId) {
		return db.delete(uploadsTable, colUploadID + "=" + rowId, null) > 0;
	}

	public Cursor getAllUploads() {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewUploads, null);
		return cur;
	}

	public Cursor getAllWaitingUploads() {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewUploads + " WHERE "
				+ colUploadStatus + "=" + StatusWaiting, null);
		return cur;
	}

	public Cursor getUpload(long id) {
		Cursor cur = db.rawQuery("SELECT * FROM " + viewUploads + " WHERE "
				+ colUploadID + "=" + id, null);
		if (cur != null) {
			cur.moveToFirst();
		}
		return cur;
	}

	public boolean updateUpload(long id, String fileName, String filePath, int status, long accountId) {
		
		ContentValues initialValues = new ContentValues();
		initialValues.put(colUploadFilename, fileName);
		initialValues.put(colUploadFilepath, filePath);
		initialValues.put(colUploadStatus, status);
		initialValues.put(colUploadAccount, accountId);
		
		int res = db.update(uploadsTable, initialValues, colUploadID + "=?", new String[] { String.valueOf(id) });
		if(res != 1)
			return false;
		return true;
	}
	
	/**
	 * This function update status in selected table
	 * 
	 * @param rowId - id of row
	 * @param status - status of selected item (upload, download)
	 * @param table - table wich should be updated
	 * @param colStatus - wich col means status
	 * @param colId - wich col means id
	 * @return if all is Ok
	 */
	public boolean updateStatus(long rowId, int status, String table, String colStatus, String colId) {
		ContentValues args = new ContentValues();
		args.put(colStatus, status);

		return db.update(table, args, colId + "=" + rowId, null) > 0;
	}	

	/**
	 * @deprecated
	 * @param rowId
	 * @return
	 */
	public boolean updateUploadDone(long rowId) {
		ContentValues args = new ContentValues();
		args.put(colUploadStatus, StatusDone);

		return db.update(uploadsTable, args, colUploadID + "=" + rowId, null) > 0;
	}

	// public int getDownloadsCount() {
	// Cursor cur = db.rawQuery("Select * from " + downloadsTable, null);
	// int x = cur.getCount();
	// cur.close();
	// return x;
	// }

	// public String GetDept(int ID) {
	// SQLiteDatabase db = this.getReadableDatabase();
	//
	// String[] params = new String[] { String.valueOf(ID) };
	// Cursor c = db.rawQuery("SELECT " + colDeptName + " FROM" + deptTable
	// + " WHERE " + colDeptID + "=?", params);
	// c.moveToFirst();
	// int index = c.getColumnIndex(colDeptName);
	// return c.getString(index);
	// }
	//	
	// public void DeleteEmp(Employee emp) {
	// SQLiteDatabase db = this.getWritableDatabase();
	// db.delete(employeeTable, colID + "=?", new String[] { String
	// .valueOf(emp.getID()) });
	// db.close();
	//
	// }

	// public Cursor getEmpByDept(String Dept) {
	// SQLiteDatabase db = this.getReadableDatabase();
	// String[] columns = new String[] { "_id", colName, colAge, colDeptName };
	// Cursor c = db.query(viewEmps, columns, colDeptName + "=?",
	// new String[] { Dept }, null, null, null);
	// return c;
	// }

	// public int GetDeptID(String Dept) {
	// SQLiteDatabase db = this.getReadableDatabase();
	// Cursor c = db.query(deptTable, new String[] { colDeptID + " as _id",
	// colDeptName }, colDeptName + "=?", new String[] { Dept }, null,
	// null, null);
	// // Cursor
	// //
	// c=db.rawQuery("SELECT "+colDeptID+" as _id FROM "+deptTable+" WHERE "+colDeptName+"=?",
	// // new String []{Dept});
	// c.moveToFirst();
	// return c.getInt(c.getColumnIndex("_id"));
	//
	// }

	// public int UpdateEmp(Employee emp) {
	// SQLiteDatabase db = this.getWritableDatabase();
	// ContentValues cv = new ContentValues();
	// cv.put(colName, emp.getName());
	// cv.put(colAge, emp.getAge());
	// cv.put(colDept, emp.getDept());
	// return db.update(employeeTable, cv, colID + "=?", new String[] { String
	// .valueOf(emp.getID()) });
	//
	// }

}
